' awk.vbs - Michael S. Sanders
' license: GPL3
' demonstrates using gawk under the visual basic scripting engine

' dimension our shell object
Dim objSH : Set objSH = WScript.CreateObject("WScript.Shell")

' declare the cmd to run and note the underscore below
' its used as a line continuation character in vbs
Dim cmd : cmd = "gawk " & chr(34) & "{print $0}" & _
chr(34) & " data.txt > file.tmp"

' test our syntax
result = msgbox(cmd, 1, "syntax okay?")

if result = 1 then
  RunProgram cmd                    ' let gawk extract data
  RunProgram "notepad.exe file.tmp" ' view results in notepad
  RunProgram "del file.tmp"         ' play nice and clean up
else
  msgbox "cancelled..."
end if

' destroy object
Set objSH = Nothing

' helper routine
Sub RunProgram(cmd)
objSH.Run "%comspec% /c " & cmd, 0, True
End Sub

' eof
